﻿using DevExpress.XtraEditors.Controls;
using RecruitStudents.Client.BLL;
using RecruitStudents.Utility;
using RecruitStudents.Utility.Const;
using RecruitStudents.Utility.Helper;
using RecruitStudents.Utility.Model;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace RecruitStudents.Client.Base
{
    public partial class Base_ExamCalculateTypeForm_Option : BaseForm
    {
        TB_Rule_CalculateScore model = null;
        ServiceBase service = new ServiceBase();
        string strDataID = string.Empty;
        public Base_ExamCalculateTypeForm_Option(string strdataid)
        {
            InitializeComponent();
            strDataID = strdataid;
            this.cmbType.Properties.NullText = "";
            this.cmbType.Properties.Columns.Add(new LookUpColumnInfo("Key", 30, "规则代码"));
            this.cmbType.Properties.Columns.Add(new LookUpColumnInfo("Value", 55, "规则名称"));
            this.cmbType.Properties.DataSource = ConstAppConfig.DicExamCalculateTypeFormType.ToList();
            this.cmbType.Properties.DisplayMember = "Value";
            this.cmbType.Properties.ValueMember = "Key";
            if (strDataID.Length > 0)
            {
                model = service.GetExamCalculateTypeFormModel(strDataID);
                if (model != null)
                {
                    //txtNo.Enabled = false;
                    model.Attach();
                    //txtNo.Text = model.CalculateScoreNo;
                    txtName.Text = model.CalculateScoreName;
                    cmbType.EditValue = model.CalculateScoreType;
                }
            }
        }

        private void simpleButton2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            //if (string.IsNullOrEmpty(txtNo.Text))
            //{
            //    DevHelper.ShowInfoMessageBox("请输入编码！");
            //    txtNo.Focus();
            //    return;
            //}
            if (string.IsNullOrEmpty(txtName.Text))
            {
                DevHelper.ShowInfoMessageBox("请输入名称！");
                txtName.Focus();
                return;
            }
            if (string.IsNullOrEmpty(cmbType.Text))
            {
                DevHelper.ShowInfoMessageBox("请选择类型！");
                cmbType.Focus();
                return;
            }
            if (model == null)
            {
                model = new TB_Rule_CalculateScore();
            }
            //model.CalculateScoreNo = txtNo.Text;
            model.CalculateScoreName = txtName.Text;
            model.CalculateScoreType = cmbType.EditValue.ToString();
            model.ExamYear = SessionerHelper.SystemYear;
            if (service.SaveExamCalculateTypeForm(model))
            {
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
        }
    }
}
